#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <pthread.h>
#include <windows.h>
#include "testcallback.h"
typedef  int  (* FN_CB)(
			char * buffer,
			int buffersize
			);

int fncallback(char *buffer,int buffersize)
{
    strcpy(buffer,"1024great");
    return strlen(buffer);
}

void * send_thread(void * arg )
{
    printf("in thread before sleep\n");
    fflush(stdout);
    Sleep(1000);
    printf("in thread after sleep\n");
    fflush(stdout);
    char buffer[1024]="init value\0";
    if ( arg !=NULL)
    {
        printf("callback is 0x%llx\n",(long unsigned long)arg);
        fflush(stdout);
        FN_CB cb_func = (FN_CB)arg;
        int ret = cb_func(buffer,sizeof(buffer));
        printf("callback %d,%s\n",ret,buffer);
        fflush(stdout);
    }else{
        printf("callback is None ");
        fflush(stdout);
    }
    return NULL;
}

void dotest(void * fncb){
	pthread_t  tid=0;
	pthread_create(&tid,NULL,send_thread,fncb);
}

#ifdef __RUN_MAIN__
int main(int argc, char **argv)
{
    printf("run main test");
    dotest((void *)fncallback);
    Sleep(5000);
    printf("end main\n");
    return 0;
}
#endif